package stringalgorithm

func CheckBracePair(braceList string) bool {
	var braceStack []rune = make([]rune, 0, len(braceList))

	for _, ch := range braceList {
		if ch == rune('(') {
			braceStack = append(braceStack, rune(')'))
		} else if ch == rune('[') {
			braceStack = append(braceStack, rune(']'))
		} else if ch == rune('{') {
			braceStack = append(braceStack, rune('}'))
		} else {
			stackLen := len(braceStack)
			if stackLen != 0 {
				if braceStack[stackLen-1] != ch {
					return false
				} else {
					braceStack = braceStack[:stackLen-1]
				}
			}
		}
	}
	if len(braceStack) != 0 {
		return false
	} else {
		return true
	}

}
